package cn.itcast.bos.system.action;

import java.util.List;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import cn.itcast.bos.base.action.BaseAction;
import cn.itcast.bos.domain.security.Menu;
import cn.itcast.bos.system.service.MenuService;

@Namespace("/")
@ParentPackage("json-default")
@Controller
@Scope("prototype")
public class MenuAction extends BaseAction<Menu>{
	@Autowired
	private MenuService menuService;
	private Logger logger=LoggerFactory.getLogger(getClass());
	@Action(value="show_menu",results={@Result(name="success",type="json")})
	public String show(){
		List<Menu> menus=menuService.show();
		ServletActionContext.getContext().getValueStack().push(menus);
		return SUCCESS;
	}
	
	@Action(value="add_menu")
	public String add(){
		if(t.getParentMenu().getId()!=null && t.getParentMenu().getId()!=0){
			logger.info("父菜单id为：{}",t.getParentMenu().getId());
		}else{
			t.setParentMenu(null);
		}
		menuService.add(t);
		
		return NONE;
	}
}
